module Main where

import Graphics.UI.WX

------------------------------------------------------------------------

sizeX, sizeY :: Int
sizeX = 800
sizeY = 300

------------------------------------------------------------------------

main :: IO ()
main = start functionFrame

functionFrame :: IO ()
functionFrame =
  do frm <- frame     [ text     := "Function Graph" ]
     pan <- panel frm [ on paint := draw ]
     set frm [ layout := minsize (sz sizeX sizeY) (widget pan) ]

------------------------------------------------------------------------

draw :: DC a -> rect -> IO ()
draw dc area =
  sequence_ [ line dc p1 p2 [] | (p1,p2) <- points `zip` tail points ]

------------------------------------------------------------------------

points :: [Point]
points =
  [ pt x (mid - round (fromIntegral ampl * cos (fromIntegral x / 30)))
  | x <- [0..sizeX]
  ]
 where
  mid  = sizeY `div` 2
  ampl = mid * 2 `div` 3
 
------------------------------------------------------------------------

